<template>
  <div>
    <div id="loader-wrapper">
      <div id="loader"></div>
      <div class="loader-section section-left"></div>
      <div class="loader-section section-right"></div>
      <div class="load_title">正在登录，请耐心等待</div>
    </div>
  </div>
</template>

<script setup>
import {useRoute, useRouter} from "vue-router";
import {getToken, setToken} from "@/utils/auth.js";

const router = useRouter()

const oauth2Login = import.meta.env.VITE_APP_OAUTH2_LOGIN;
if(oauth2Login !== 'true' && oauth2Login !== true){
  router.push({ path: "/login"})
}else{
  doOAuth2Login()
}

function doOAuth2Login() {
  const route = useRoute();
  const token = route.query.oauth2LoginToken;
  if (token) {
    setToken(token);
    router.push({ path: "/" })
  }else{
    const baseAPi = import.meta.env.VITE_APP_BASE_API;
    let url = `${window.location.origin}${baseAPi}/sso/oauth2/loginEnter`
    url += `?origin=${encodeURIComponent(window.location.origin)}&token=${getToken()}`;
    window.location.href = url;
  }
}

</script>

<style scoped>

</style>
